package com.spy.system.controller;

import com.spy.common.core.domain.R;
import com.spy.system.dto.MatMaterialPageReqDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.spy.common.annotation.Log;
import com.spy.common.core.controller.BaseController;
import com.spy.common.core.domain.AjaxResult;
import com.spy.common.enums.BusinessType;
import com.spy.system.domain.MatMaterial;
import com.spy.system.service.IMatMaterialService;
import com.spy.common.utils.poi.ExcelUtil;
import com.spy.common.core.page.TableDataInfo;

/**
 * 物料信息Controller
 *
 * @author ruoyi
 * @date 2025-11-09
 */
@RestController
@RequestMapping("/system/material")
@Api(tags = "物料信息相关接口")
public class MatMaterialController extends BaseController
{
    @Autowired
    private IMatMaterialService matMaterialService;

/**
 * 查询物料信息列表
 */
@PreAuthorize("@ss.hasPermi('system:material:list')")
@GetMapping("/list")
@ApiOperation("查询物料信息列表")
    public TableDataInfo list(@ApiParam(value = "物料信息查询条件") MatMaterialPageReqDto matMaterialPageReqDto)
    {
     return   matMaterialService.selectMatMaterialList(matMaterialPageReqDto);

    }



    /**
     * 获取物料信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:material:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取物料信息详细信息")
    public R<MatMaterial> getInfo(@ApiParam(value = "物料信息ID", required = true)
                                   @PathVariable("id") Long id)
    {
                return R.ok(matMaterialService.selectMatMaterialById(id));
    }

    /**
     * 新增物料信息
     */
    @PreAuthorize("@ss.hasPermi('system:material:add')")
    @Log(title = "物料信息", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增物料信息")
    public AjaxResult add(@ApiParam(value = "物料信息实体", required = true) @RequestBody MatMaterial matMaterial)
    {
        return toAjax(matMaterialService.insertMatMaterial(matMaterial));
    }

    /**
     * 修改物料信息
     */
    @PreAuthorize("@ss.hasPermi('system:material:edit')")
    @Log(title = "物料信息", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改物料信息")
    public AjaxResult edit(@ApiParam(value = "物料信息实体", required = true)  @RequestBody MatMaterial matMaterial)
    {
        return toAjax(matMaterialService.updateMatMaterial(matMaterial));
    }

    /**
     * 删除物料信息
     */
    @PreAuthorize("@ss.hasPermi('system:material:remove')")
    @Log(title = "物料信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除物料信息")
    public AjaxResult remove(@ApiParam(value = "物料信息ID数组", required = true) @PathVariable Long[] ids)
    {
        return toAjax(matMaterialService.deleteMatMaterialByIds(ids));
    }
}